// pages/subject/subject.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    timer: '',
    wrongSum: 8,
    notMaster:0,

    subjectList:[],
    unionid:""
  },
  queryProblem(e){
    var that = this;
    console.log(that.unionid);
    // var that = this;
    var id = e.currentTarget.id;
    console.log("herehere*******subjectName:");


    console.log("herehere*******subjectName:"+id);
    wx.navigateTo({
      url: "../errlist/errlist?subject=" + id + "&unionid=" + getApp().globalData.uid,
      success: function () { }        //成功后的回调；
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let that = this;

    wx.request({
      url: 'http://localhost:8080/eb-back-web/subject',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: { grade: options.grade ,unionid:options.unionid},
      success: function (res) {
        //点击年级
        let grade = res.data.subject;
        //错题总数（传给下页显示）
        let wrongNum = that.data.wrongSum;
        that.setData({
          wrongSum:options.wrongNum,
          subjectList:res.data,
          unionid:options.unionid

        });
        //绘制中间圆圈
        let sum = that.data.wrongSum;
        let master = that.data.wrongSum - that.data.notMaster;
        let completePercent = parseInt((master / sum) * 100);
        that.getResultComment(completePercent);
        that.showScoreAnimation(master, sum);
      },
      fail: function () {
        console.log('跳转科目页出错')
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  showScoreAnimation: function (rightItems, totalItems) {
    /*
    cxt_arc.arc(x, y, r, sAngle, eAngle, counterclockwise);
    x	                    Number	  圆的x坐标
    y	                    Number	  圆的y坐标
    r	                    Number	  圆的半径
    sAngle	            Number	  起始弧度，单位弧度（在3点钟方向）
    eAngle	            Number	  终止弧度
    counterclockwise	    Boolean	  可选。指定弧度的方向是逆时针还是顺时针。默认是false，即顺时针。
    */
    let that = this;
    let copyRightItems = 0;
    that.setData({
      timer: setInterval(function () {
        copyRightItems++;
        if ((copyRightItems - rightItems) == 1) {
          clearInterval(that.data.timer)
        } else {
          // 页面渲染完成
          // 这部分是灰色底层
          let cxt_arc = wx.createCanvasContext('canvasArc');//创建并返回绘图上下文context对象。
          cxt_arc.setLineWidth(6);//绘线的宽度
          cxt_arc.setStrokeStyle('#e4e4e4');//绘线的颜色
          cxt_arc.setLineCap('round');//线条端点样式
          cxt_arc.beginPath();//开始一个新的路径
          cxt_arc.arc(53, 53, 50, 0, 2 * Math.PI, false);//设置一个原点(53,53)，半径为50的圆的路径到当前路径
          cxt_arc.stroke();//对当前路径进行描边
          //这部分是蓝色部分
          cxt_arc.setLineWidth(6);
          cxt_arc.setStrokeStyle('#ff777a');
          cxt_arc.setLineCap('round')
          cxt_arc.beginPath();//开始一个新的路径
          cxt_arc.arc(53, 53, 50, -Math.PI * 1 / 2, 2 * Math.PI * (copyRightItems / totalItems) - Math.PI * 1 / 2, false);
          cxt_arc.stroke();//对当前路径进行描边
          cxt_arc.draw();
        }
      }, 20)
    })
  },

  getResultComment: function (completePercent) {
    let that = this;
    that.setData({
      resultComment: completePercent + "%"
    })
  },

})
